package com.zuowei.ycy.user.ui.index;

import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.and.yzy.frame.util.RetrofitUtils;
import com.facebook.drawee.view.SimpleDraweeView;
import com.zuowei.ycy.R;
import com.zuowei.ycy.user.domain.GoodDetailInfo;
import com.zuowei.ycy.user.http.Merchant;
import com.zuowei.ycy.ui.BaseAty;
import com.zuowei.ycy.user.util.AppJsonUtil;

import butterknife.Bind;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;

/**
 * 商品详情
 */
public class GoodDetailAty extends BaseAty {

    @Bind(R.id.iv_good)
    SimpleDraweeView mIvGood;
    @Bind(R.id.tv_name)
    TextView mTvName;
    @Bind(R.id.tv_sale_num)
    TextView mTvSaleNum;
    @Bind(R.id.tv_price)
    TextView mTvPrice;
    @Bind(R.id.tv_content)
    TextView mTvContent;
    @Bind(R.id.iv_finish)
    ImageView mIvFinish;

    @Override
    public int getLayoutId() {
        return R.layout.index_good_detail;
    }

    @Override
    public void initData() {
        mIvFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    @Override
    public void requestData() {
        showLoadingContentDialog();
        doHttp(RetrofitUtils.createApi(Merchant.class).merchantGoodsInfo(getIntent().getExtras().getString("goods_id")), 0);

    }


    @Override
    public boolean setIsInitRequestData() {
        return true;
    }


    @Override
    public void onSuccess(String result, Call<ResponseBody> call, Response<ResponseBody> response, int what) {

        switch (what) {
            case 0:
                GoodDetailInfo home = AppJsonUtil.getObject(result, GoodDetailInfo.class);
                mIvGood.setImageURI(Uri.parse(home.getGoods_picture()));
                mTvName.setText(home.getGoods_name());
                mTvSaleNum.setText("销量" + home.getSales() + "单");
                mTvPrice.setText("￥" + home.getGoods_price());
                mTvContent.setText(home.getGoods_detail());
                break;


        }
        super.onSuccess(result, call, response, what);
    }


}